package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@RequestMapping("/user")
@Controller
public class UserController {

    @Autowired
    private UserService userService;
    /*查询*/
    @RequestMapping("/findList")
    public String findList(Model model){
        List<User> list = userService.findList();
        model.addAttribute("list",list);
        System.out.println("==================================");
        return "findList";
    }

    @RequestMapping("ad")
    public String ad(){
        return "add";
    }

    @RequestMapping("add")
    public String insertUser(User user){
        userService.insertUser(user);
        return "redirect:findList";
    }

    @RequestMapping("del")
    public String del(Integer userId){
        userService.del(userId);
        return "redirect:findList";
    }

    @RequestMapping("upd")
    public String upd(Integer userId,Model model){
        User user= userService.upd(userId);
        model.addAttribute("user" ,user);
        return "update";
    }

    @RequestMapping("update")
    public String update(User user){
        userService.update(user);
        return "redirect:findList";
    }
}
